AC_PREREQ([2.69])


m4_define([tr_ace_major_version], [1])
m4_define([tr_ace_minor_version], [0])
m4_define([tr_ace_impl_version], [0])
m4_define([tr_ace_impl_fix], [0])

m4_define([tr_ace_version], [tr_ace_major_version.tr_ace_minor_version.tr_ace_impl_version])

AC_INIT([tr-ace],[tr_ace_version], [], [], [tocai.com])


TR_MAJOR_VERSION=tr_ace_major_version
AC_SUBST(TR_MAJOR_VERSION)

TR_MINOR_VERSION=tr_ace_minor_version
AC_SUBST(TR_MINOR_VERSION)

TR_IMPL_VERSION=tr_ace_impl_version
AC_SUBST(TR_IMPL_VERSION)

TR_VERSION=tr_ace_version
AC_SUBST(TR_VERSION)

AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror])
#AC_CONFIG_SRCDIR([include/xxx.h])
AC_CONFIG_HEADERS([config.h])

AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AM_PROG_CC_C_O
AM_PROG_AR

AC_SUBST([LIBTOOL_DEPS])
AM_PROG_LIBTOOL

PKG_PROG_PKG_CONFIG

AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

TR_CFLAGS="$TR_CFLAGS -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes"
TR_CFLAGS="$TR_CFLAGS -Wmissing-declarations -Wold-style-definition -Wpointer-arith"
TR_CFLAGS="$TR_CFLAGS -Wcast-align -Wnested-externs -Wcast-qual -Wformat-nonliteral"
TR_CFLAGS="$TR_CFLAGS -Wformat-security -Wundef -Wwrite-strings"
TR_CFLAGS="$TR_CFLAGS -std=c99"

# Extra flags for example to suppress certain warning types
TR_CFLAGS="$TR_CFLAGS $TR_CFLAGS_EXTRA"

TR_CPPFLAGS="$TR_CPPFLAGS"

AM_CFLAGS="$AM_CFLAGS $TR_CFLAGS"
AM_CXXFLAGS="-std=c++11"
AM_CPPFLAGS="$AM_CPPFLAGS $TR_CPPFLAGS"

AC_CONFIG_FILES([
  Makefile
  src/Makefile
  libtp/Makefile
])

AC_ARG_WITH(config_path, [--with-config-path=PATH for config],  
  TR_CONFIG_PATH=$withval, TR_CONFIG_PATH=${sysconfdir}/tr-ace)
AC_SUBST(TR_CONFIG_PATH)

AC_CHECK_PROGS([PKGCONFIG], [pkg-config])
if test -z "$PKGCONFIG"; then
	AC_MSG_ERROR([Please install pkg-config])
fi

if test $enable_static = "yes" ; then
	export PKG_CONFIG="pkg-config --static"
fi

PKG_CHECK_MODULES([EL], [libel])
AC_SUBST([EL_CFLAGS])
AC_SUBST([EL_LIBS])

PKG_CHECK_MODULES([BOLT], [libbolt])
AC_SUBST([BOLT_CFLAGS])
AC_SUBST([BOLT_LIBS])

PKG_CHECK_MODULES([PROT], [libprot])
AC_SUBST([PROT_CFLAGS])
AC_SUBST([PROT_LIBS])


AM_CONDITIONAL([HAVE_PKGCONFIG], [test -n "$PKGCONFIG"])
#AM_COND_IF([HAVE_PKGCONFIG], [AC_CONFIG_FILES([pkgconfig/Makefile])])
#AM_COND_IF([HAVE_PKGCONFIG], [AC_CONFIG_FILES([pkgconfig/libbolt.pc])])

AC_SUBST([LIBS])
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

CC_VERSION=$($CC --version | head -n 1)

AC_OUTPUT

AC_MSG_RESULT([
	$PACKAGE $VERSION
	=================
	TR-ACE version:		  ${TR_VERSION}

	host:			        ${host}
	prefix:			      ${prefix}
	sysconfdir:		    ${sysconfdir}
	libdir:			      ${libdir}
	includedir:		    ${includedir}

	cc:			          ${CC}
	cc version:		    ${CC_VERSION}
	cppflags:		      ${CPPFLAGS}
	am_cppflags:		  ${AM_CPPFLAGS}
	cflags:			      ${CFLAGS}
	am_cflags:		    ${AM_CFLAGS}
	am_cxxflags:		  ${AM_CXXFLAGS}
	ldflags:		      ${LDFLAGS}
	am_ldflags:		    ${AM_LDFLAGS}
	])





